package de.acagamics.roteschlupfmuetze.io;

import java.io.*;  
import java.beans.*;

/**
 * @author Enrico Gebert
 *
 */
public class XMLDataWriter<T> {

	public boolean WriteXMLFile(String filename, T data) {
		// Serialize 
		boolean result = true;
	    XMLEncoder enc = null; 
		// Java SE7 Feature try with resources. It ensures that the loaded
		// resource will be closed after usage even if an error occurs.
	    try /*(XMLEncoder enc = new XMLEncoder( new FileOutputStream(filename) ))*/
	    { 
	      enc = new XMLEncoder( new FileOutputStream(filename) ); 
	      enc.writeObject( data ); 
	    } 
	    catch ( IOException e ) { 
	      e.printStackTrace(); 
	      result = false;
	    } 
	    finally { 
		      if ( enc != null ) 
		        enc.close(); 
		    }
		return result;
	}
}
